@using Microsoft.AspNetCore.Components;
@inject NavigationManager navigationManager
@inject IStringLocalizer<Global> L
@implements IDynamicComponent

<MatNavItem Href="@navigationManager.ToAbsoluteUri(" ").AbsoluteUri" NavLinkMatch="NavLinkMatch.All">
    <MatIcon>home</MatIcon> <span class="miniHover">@L["AppNavHome"]</span>
</MatNavItem>

<MatNavItem Href="@navigationManager.ToAbsoluteUri("todo_list").AbsoluteUri">
    <MatIcon>list_alt</MatIcon> <span class="miniHover">@L["TodoNav"]</span>
</MatNavItem>

<MatNavSubMenu>
    <MatNavSubMenuHeader>
        <MatNavItem AllowSelection="false">
            <MatIcon>stars</MatIcon><span class="miniHover"> @L["AppNavFeatures"]</span>
        </MatNavItem>
    </MatNavSubMenuHeader>
    <MatNavSubMenuList>
        <MatNavItem Href="@navigationManager.ToAbsoluteUri("drag_and_drop").AbsoluteUri">
            <MatIcon>touch_app</MatIcon> <span class="miniHover">@L["AppNavDragAndDrop"]</span>
        </MatNavItem>
    </MatNavSubMenuList>
</MatNavSubMenu>

<MatNavItem Href="@navigationManager.ToAbsoluteUri("dashboard").AbsoluteUri" Disabled="@(!IsLoggedIn)">
    <MatIcon>bar_chart</MatIcon> <span class="miniHover">@L["Dashboard"]</span>
</MatNavItem>

<MatNavSubMenu>
    <MatNavSubMenuHeader>
        <MatNavItem AllowSelection="false" Disabled="@(!IsLoggedIn)">
            <MatIcon>mail_outline</MatIcon>
            <span class="miniHover"> @L["AppNavEmail"]</span>
        </MatNavItem>
    </MatNavSubMenuHeader>
    <MatNavSubMenuList>
        <MatNavItem Href="@navigationManager.ToAbsoluteUri("email_view").AbsoluteUri" Disabled="@(!IsLoggedIn)">
            <MatIcon>inbox</MatIcon> <span class="miniHover">@L["AppNavReadEmail"]</span>
        </MatNavItem>
        <MatNavItem Href="@navigationManager.ToAbsoluteUri("email").AbsoluteUri" Disabled="@(!IsLoggedIn)">
            <MatIcon>send</MatIcon> <span class="miniHover">@L["AppNavSendEmail"]</span>
        </MatNavItem>
    </MatNavSubMenuList>
</MatNavSubMenu>

<MatNavItem Href="@navigationManager.ToAbsoluteUri("forum").AbsoluteUri" Disabled="@(!IsLoggedIn)">
    <MatIcon>forum</MatIcon> <span class="miniHover">@L["AppNavForum"]</span>
</MatNavItem>

<MatNavItem Href="@navigationManager.ToAbsoluteUri("sponsors").AbsoluteUri">
    <MatIcon>attach_money</MatIcon> <span class="miniHover">@L["AppNavSponsors"]</span>
</MatNavItem>

@code {

    public int Order { get => 1; }
    public string IntoComponent { get => "NavMenu"; }

    public bool IsLoggedIn = false;

    [CascadingParameter]
    Task<AuthenticationState> authenticationStateTask { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        IsLoggedIn = false;
        var user = (await authenticationStateTask).User;

        if (user.Identity.IsAuthenticated)
        {
            IsLoggedIn = true;
        }

        if (user.IsInRole(DefaultRoleNames.Administrator))
        {
            // Perform some action only available to users in the 'admin' role
            //Console.WriteLine(DefaultRoleNames.Administrator);
        }
    }
}
